#include "mainscene.h"
#include "ui_mainscene.h"

MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);

    this->setWindowTitle("coin");
    this->setFixedSize(QSize(320, 588));
    this->setWindowIcon(QIcon(":/Coin0001.png"));
    // 准备点击按钮的音效
    QSound* startSound = new QSound(":/TapButtonSound.wav", this);

    // 退出
    connect(ui->actionquit, &QAction::triggered, this, [=](){
        close();
    });

    MyPushButton* start = new MyPushButton(":/MenuSceneStartButton.png");
    start->setParent(this);
    start->show();
    start->move(this->width() * 0.5 - start->width() * 0.5, this->height() * 0.7 );

    // 创建出第二个场景
    chooseLevelScene = new ChooseLevelScene(this);

    // 移动
    connect(start, &MyPushButton::clicked, this, [=](){
        qDebug()<<"button clicked";
        start->zoomUp();
        start->zoomDown();
        startSound->play();
        QTimer::singleShot(500, this, [=](){
            this->hide();
            chooseLevelScene->show();
        });

    });
}

void MainScene::paintEvent(QPaintEvent *event){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/PlayLevelSceneBg.png");
    painter.drawPixmap(0, 0, this->width(), this->height(),pix);
    // 绘制标题
    pix.load(":/Title.png");
    painter.drawPixmap(20, 30, pix.width() * 0.5, pix.height() * 0.5, pix);
}

MainScene::~MainScene()
{
    delete ui;
}

